package datastructure

import scala.collection.mutable.ArrayBuffer
object ArrayApp extends App {
  // 1
  val a = new Array[String](5)
  a(0) = "hello"

  // 2
  val b = Array("Spark", "Hadoop", "storm")       // 类名 + () 调用的是 object里面 apply()方法

  val c = Array(1,2,3,4,5)
  println(c.sum)
  println(c.max)
  println(c.mkString("<",",",">"))

  // 3. 可变数组
  var d = ArrayBuffer[Int]()
  d += 1
  d += 2
  d += (3,4,5)
  d ++= Array(6,7,8,9)
  d.insert(0,0)
  d.remove(3)
  d.trimEnd(1)
  d.trimStart(1)
  println(d)
  for(el <- d){
    print(el)
  }
  println()
  for(i <- d.indices){    // i <- 0 until c.length
    print(d(i))
  }
  println()
  for(i <- d.indices.reverse){    // 逆序输出
    print(d(i))
  }
  println(d.mkString)
}
